package com.burgeon.backend.EnterpriseWeChat.rest.Gtasks;



import com.burgeon.backend.Rest.base.RESTBase;
import org.apache.http.util.TextUtils;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class saveBirthdayInvite extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public saveBirthdayInvite(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public void getData(String cardNo,String type,String date,String inviteWay,
                        String content,String feedback,String remark,String empId,String tarGetDate, String code) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(cardNo, type, date, inviteWay, content, feedback, remark, empId,tarGetDate,code), url);
        System.err.println("str="+str);
        String code1 = new JSONArray(str).getJSONObject(0).getString("code");

        if (!"0".equals(code1)) {
            throw new Exception(str);
        }

    }

    private MultiValueMap Data(String cardNo,String type,String date,String inviteWay,
                               String content,String feedback,String remark,String empId,String tarGetDate,
                                String code) {
        date.replaceAll("-","");

        HashMap params = new HashMap();
        params.put("'C_VIP_ID__CARDNO'",cardNo);
        params.put("'BILLTYPE'",type);

        if (!TextUtils.isEmpty(date)) {
            params.put("'BILLDATE'",date);
        }
        if (!TextUtils.isEmpty(inviteWay)) {
            params.put("'VISITTYPE'","'"+inviteWay+"'");
        }
        if (!TextUtils.isEmpty(content)) {
            params.put("'RVISIT_CONTENT'","'"+content+"'");
        }

        if (!TextUtils.isEmpty(feedback)) {
            params.put("'FEEDBACK'","'"+feedback+"'");
        }
        if (!TextUtils.isEmpty(remark)) {
            params.put("'DESCRIPTION'","'"+remark+"'");
        }
        if (!TextUtils.isEmpty(tarGetDate)) {
            params.put("'TARGET_DATE'","'"+tarGetDate+"'");
        }
        //款号
        if (!TextUtils.isEmpty(code)) {
            params.put("'M_PRODUCT_ID__NAME'","'"+code+"'");
        }

        params.put("'HR_EMPLOYEE_ID__NAME'","'"+empId+"'");

        params.put("table", "C_VIP_APPRVISIT");//表名
        System.err.println(params);

        return DATA("ObjectCreate", params, account, password);
    }


    public static void main(String[] args) {
        saveBirthdayInvite g = new saveBirthdayInvite("39.104.73.78:5321", "nea@burgeon.com.cn", "burgeon5321");
        try {
            String con="亲爱的**女士，穿搭是一种表达，时尚是一种诠释。您如何保持精致？M essential就是您的理想答案。↵最近限量新品上线，等待您的宠幸！种草新品的意义在于别人翻遍衣橱时，您已经潇洒的出门。↵这个季节，带您遇见不一样的自己！";
            g.getData("13920619135","4","20210205","3", con,"2","","马婧怡","","");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
